package carol.pvp.merger.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import carol.pvp.producer.basicType.AssCode;

public class CodeManager {
	Map<String,ArrayList<AssCode>> codeMap = new HashMap<String,ArrayList<AssCode>>();
	
	protected Map<String,ArrayList<AssCode>> classifyCodes(ArrayList<AssCode> codes){
		
		while(codes.size()>0){
			String packageName = codes.get(0).getPackageName();
			String className = codes.get(0).getClassName();
			
			ArrayList<AssCode> classCodes = getClassCodes(packageName,className,codes);
			codeMap.put(packageName.replace(".", "\\\\")+"\\\\"+className+".java", classCodes);
			
			codes = getRestCodes(classCodes,codes);
		}
		
		return codeMap;
	}
	
	private ArrayList<AssCode> getClassCodes(String packageName, String className, ArrayList<AssCode> codes){
		ArrayList<AssCode> classCodes = new ArrayList<AssCode>();
		
		for(int i=0;i<codes.size();i++){
			AssCode code = codes.get(i);
			if(code.getPackageName()==packageName&&code.getClassName()==className){
				classCodes.add(code);
			}
		}
		
		return classCodes;
	}
	
	private  ArrayList<AssCode> getRestCodes(ArrayList<AssCode> classCodes, ArrayList<AssCode> codes){
		
		for(int i=0;i<classCodes.size();i++){
			codes.remove(classCodes.get(i));
		}
		
		return codes;
	}
}
